package com.jason.hadoop.driver;

import com.jason.hadoop.bean.WordBean;
import com.jason.hadoop.bean.WordOrderBean;
import com.jason.hadoop.group.WordOrderGroup;
import com.jason.hadoop.group.WordOrderPartitioner;
import com.jason.hadoop.map.WordOrderMap;
import com.jason.hadoop.reduce.WordOrderReduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


public class WordOrderDriver  {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(WordOrderDriver.class);
        job.setMapperClass(WordOrderMap.class);
        job.setReducerClass(WordOrderReduce.class);

        job.setMapOutputKeyClass(WordBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(WordOrderBean.class);
        job.setOutputValueClass(WordOrderBean.class);
        job.setGroupingComparatorClass(WordOrderGroup.class);


        FileInputFormat.setInputPaths(job, new Path("E:/work/lagou/hadoopin"));
        FileOutputFormat.setOutputPath(job, new Path("E:/work/lagou/hadoopout"));

        job.setPartitionerClass(WordOrderPartitioner.class);
        job.setNumReduceTasks(1);

        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);

    }
}
